﻿using UnityEngine;
using System.Collections;

public class NeutralSpawner : MonoBehaviour {
	public Player neutral;
	public GameObject spawnUnit;
	public Rect spawnBounds;
	public static NeutralSpawner singleton;
	// Use this for initialization
	void Start () {
		singleton=this;
	}
	
	// Update is called once per frame
	void Update () {
		if(neutral.getUnits().Count<15){
			float difficulty= Random.value;
			Vector3 pos = new Vector3(Random.value*spawnBounds.width+spawnBounds.xMin,0,Random.value*spawnBounds.height+spawnBounds.yMin);
			GameObject newUnit=(GameObject)Instantiate(spawnUnit,pos,spawnUnit.transform.rotation);
			Unit u = (Unit)newUnit.GetComponent("Unit");
			Vector3 tmp = newUnit.transform.localScale;
			tmp.x=tmp.y=tmp.z=Mathf.Max(1.5f*difficulty+.7f,.7f);
			newUnit.transform.localScale= tmp;
			u.attackDamage=100*difficulty;
			u.attackSpeed= 1.5f*(1-difficulty);
			u.attackRange=15;
			u.health= 2000*difficulty+500;
			u.goldValue=40+(int)(200*difficulty);
			neutral.addUnit(u);
			//u.obj.renderer.material.color= new Color(165f/255*difficulty,42f/255*difficulty,42f/255*difficulty);
			u.owner=neutral;
		}
	}
}
